wx.date = (format = 'Y-m-d H:i:s', timestamp = '') =>{
  var d = timestamp == '' ? new Date() : new Date(parseInt(timestamp) * 1000);
  format = format.replace("Y", d.getFullYear());
  format = format.replace("m", (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : d.getMonth() + 1);
  format = format.replace("d", d.getDate() < 10 ? '0' + d.getDate() : d.getDate());
  format = format.replace("H", d.getHours());
  format = format.replace("i", d.getMinutes());
  format = format.replace("s", d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds());
  return format;
}

wx.time = (format = '') =>{
  return format == '' ? Date.parse(new Date()) / 1000 : Date.parse(new Date(format)) / 1000;
}

wx.ajax = (obj) =>{
  wx.request({
    url: obj.url,
    data: obj.data ? obj.data:{},
    method: obj.type ? obj.type:'POST',
    header: obj.header ? obj.header : { "Content-Type": "application/x-www-form-urlencoded" },
    success(res){
      typeof obj.success == 'function' ? obj.success(res) : console.error('The callback method is a function.');
    },
    fail(res){
      typeof obj.error == 'function' ? obj.error(res) : console.error('The callback method is a function.');
    }
  })
}

wx.getDate = (count = 7) =>{
  let d = new Date();
  let MonthName = (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1);
  let DateName = d.getDate()<10 ? '0' + d.getDate() : d.getDate();
  let result = [d.getFullYear() + '-' + MonthName + '-' + DateName+' '+'今天'];
  for(let i = 0;i<count;i++){
    d.setDate(d.getDate() + 1);
    let y = d.getFullYear(), m = (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : d.getMonth() + 1,n = '',day = d.getDay();
    if(i==0){
      n = '明天'
    }else{
      if (day == 0) { n = '星期天'; } else if (day == 1) { n = '星期一'; } else if (day == 2) { n = '星期二'; } else if (day == 3) { n = '星期三'; } else if (day == 4) { n = '星期四'; } else if (day == 5) { n = '星期五'; } else if (day == 6) { n = '星期六'; }
    }
    let newDateName = d.getDate() < 10 ? '0' + d.getDate() : d.getDate();
    result.push(y + '-' + m + '-' + newDateName + ' ' + n);
  };
  return result;
}

wx.regData = {
  chinese: /^[\u4e00-\u9fa5]$/, /*仅中文*/
  CED: /^([A-Za-z\d]|[\u4E00-\u9FA5])+$/, /*中文、字母、数字*/
  chiEng: /^([A-Za-z]|[\u4E00-\u9FA5])+$/, /*中文和字母*/
  numEng: /^[A-Za-z0-9]+$/, /*^[A-Za-z0-9]{4,40}$/;英文和数字*/
  posnum: /^[1-9]\d*$/, /*正整数*/
  num: /^\d{1}$/, /*只能有数字切不能为空*/
  pass: /([^\s\u4E00-\u9FA5]){6,20}$/, /*密码*/
  personName: /[\u4E00-\u9FA5]{2,10}(?:·[\u4E00-\u9FA5]{2,10})*/, /*人的姓名*/
  letter: /^[A-Za-z]+$/, /*字母*/
  notnulls: /\S/, /*不能为空*/
  filsenulls: /^\S/, /*第一个字符不能为空格*/
  notspan: /^[^\s]+$/, /*不能有空格*/
  notnull: /^\S+$/, /*不能有空格并且不能为空*/
  notspe: new RegExp("[\^\\`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]"), /*不能有特殊字符*/
  tel: /^1[1-9]\d{9}$/, /*手机号*/
  email: /\w+((-w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+/, /*邮箱*/
}
wx.getElem = (e,name = '',isForm = false)=>{
  let dataset = isForm ? e.detail.value:e.currentTarget.dataset;
  if (name!=''){
    if (dataset[name]) {
      return dataset[name];
    }else{
      return '获取参数不存在,请检查';
    }
  }else{
    return dataset;
  }
}
wx.RndNum=(n = 6)=>{
  var rnd = "";
  for (var i = 0; i < n; i++)
    rnd += Math.floor(Math.random() * 10);
  return rnd;
}